package com.edaoe.interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import com.jfinal.kit.LogKit;
import com.edaoe.common.Ret;

/**
 * Created by Dull on 2017/5/29 0029.
 */
public class GlobalInterceptor implements Interceptor {

    public void intercept(Invocation inv) {
        Controller c = inv.getController();
        c.getResponse().addHeader("Access-Control-Allow-Origin", "*");
        try {
            inv.invoke();
        } catch (Exception e) {
            LogKit.error(e.getMessage(), e);
            c.renderJson(Ret.error(-1));
        }
    }
}
